// 逆波兰表达式求值 即 后缀表达式 左右中
#include<iostream>
#include<vector>
#include<string>
#include<stack>

class Solution {
public:
    int evalRPN(std::vector<std::string>& tokens) {
        std::stack<long long> st;
        for(int i = 0; i < tokens.size(); i++){
            if(tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/"){
                long long num1 = st.top();
                st.pop();
                long long num2 = st.top();
                st.pop();
                if (tokens[i] == "+") st.push(num2 + num1);
                if (tokens[i] == "-") st.push(num2 - num1);
                if (tokens[i] == "*") st.push(num2 * num1);
                if (tokens[i] == "/") st.push(num2 / num1);
            }else{
                st.push(std::stoi(tokens[i])); // 将字符串转换为整数并压入栈中
            }
        }
        int result = st.top();
        st.pop();
        return result;
    }
};

int main()
{
    Solution s;
    std::vector<std::string> tokens = {"10","6","9","3","+","-11","*","/","*","17","+","5","+"};
    std::cout << s.evalRPN(tokens) <<std::endl;
    return 0;
}